<template>
	<view class="notice_box">
		<view class="box" v-for="(item,index) in noticeList" :key="item.id" @tap="goDetails(item.id,index)">
			<view class="image">
				<image :src="item.picture" mode="aspectFit"></image>
			</view>
			<view class="title">
				<view class="title1">{{ item.title }}</view>
				<view class="title2">{{ item.content }}</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { pushNotice, updateNotice,getNotice } from '@/api/homes/notice/notice.js'
	
	export default {
		data() {
			return {
				noticeList: []
			}
		},
		onLoad() {
			this.getNoticeData()
			this.getNoticeByUserId()
		},
		methods: {
			async getNoticeByUserId() {
				await getNotice().then(res=>{
					console.log("ddddddddd",res);
					this.noticeList = res.data
				})
				 
			},
			
			async getNoticeData() {
				const { data } = await pushNotice()
				if (data) {
					return
				} else {
					this.noticeList = [...this.noticeList,data]
				}
				
			},
			 async goDetails(id,index) {
				const { code } = await updateNotice(id, 1)
				const data = JSON.stringify(this.noticeList[index])
				if (code === 200) {
					uni.navigateTo({
						url: '/pages/homes/noticeDetails/noticeDetails?data='+data
					})
					// uni.navigateTo({
					// 	url:"/pages/homes/passageReading/passageReading?notice="+true
					// })
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background: $uni-bg-color-page;
		
	}
.notice_box {
	padding: 30rpx;
	// height: 100vh;
	// background: $uni-bg-color-page;
	
	.box {
		width: 100%;
		background-color: #ffffff;
		margin-bottom: 30rpx;
		border-radius: 10rpx;
		overflow: hidden;
		
		.image {
			width: 100%;
			height: 394rpx;
			
			image {
				width: 100%;
				height: 100%;
			}
			
		}
		
		.title {
			padding: 16rpx 30rpx;
			
			.title1 {
				font-size: 32rpx;
			}
			
			.title2 {
				margin-top: 10rpx;
				font-size: 24rpx;
				color: $uni-text-color;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
			}
		}
	}
}
</style>
